const Koa = require('koa');
const serve = require('koa-static');
const path = require('path');
const chalk = require('chalk');
const Router = require('koa-router');
const router = new Router();

const PORT = 5000;
const HOST = 'localhost';

const app = new Koa();

router.post('/post', (ctx, next) => {

    return new Promise((resolve,reject)=>{
        setTimeout(() => {
            ctx.body = {
                data: 555,
            };
            resolve(next)
        }, 5000);
    })
});

app
.use(serve(path.join(__dirname, '/dist')))
.use(router.routes())
.listen(PORT, () => {
    console.log(
        '\n' +
        chalk.bgGreen.black(' OPEN ') +
        ' Server listening on ' +
        chalk.green(`http://${HOST}:${PORT}\n`)
    );
});